home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #2 / Monster Media No. 2 (Monster Media)(1994).ISO / database / bltw110.zip / BW_LAI10.C < prev    next >
C/C++ Source or Header  |  1994-08-18  |  7KB  |  285 lines

  1.  
  2. #include <dos.h>
  3. #include <conio.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <time.h>
  8.  
  9. #include "BULLET.h"
  10.  
  11. #pragma pack(1)        /* C7 packs to EVEN by default
  12.             Must pack any Bullet-used data 
  13.             structures to standard byte-
  14.             alignment with any compiler! 
  15.             YOUR PROGRAM WILL NOT RUN CORRECTLY
  16.             UNLESS THIS IS SO!
  17.             */
  18.                
  19. /* 
  20.    12-Jul-94
  21.    BW_LAI10.C -chh
  22.    
  23.    The RC resource compiler may generate a warning about the use of
  24.    hard-code data segment loads with the DGROUP value.  The warning is
  25.    relevant to a multi-instanced program, which Bullet code won't be
  26.    (can't be). Future versions will remove this limitation (i.e., a 
  27.    DLL version will be available).
  28.                    
  29. */
  30.    
  31.             
  32. /* --test raw speed using 32-bit long integer key, unique
  33.    1) this test uses a non-standard binary field as a sort field
  34.    2) this code is for raw speed tests--it's straight inline
  35.     
  36.     
  37.     BW_LAI10.C requires Windows be in ENHANCED MODE
  38.     see BW_LAI11.C for an example of using Bullet in Standard mode
  39.     
  40.        
  41.    Note: memory model must be medium, large, or huge */
  42.  
  43. struct memorypack MP;
  44. struct initpack IP;
  45. struct exitpack EP;
  46. struct fielddesctype fieldlist[2];
  47. struct createdatapack CDP;
  48. struct createkeypack CKP;
  49. struct dosfilepack DFP;
  50. struct openpack OP;
  51. struct accesspack AP;
  52. struct exitpack EP;
  53.  
  54. int    rez, level;
  55. div_t    div_rez;
  56. time_t    starttime, endtime;
  57.  
  58. char    tmpstr[129];
  59.  
  60. char     NameDAT[] = ".\\BINTEST.DBB";
  61. char     NameIX1[] = ".\\BINTEST.IX1";
  62.  
  63. char    kx1[] = "CODENUMBER";
  64.  
  65. unsigned handdat, handix1;
  66.  
  67. struct testrectype {
  68.     char  tag;
  69.     long  codenumber;
  70.     char  codename[11];
  71. }; /* test program record length=16 bytes */
  72. struct testrectype testrec;
  73.  
  74. char    keybuffer[64];        /* MUST supply a work buffer for keys */
  75.                             /* a single one can be shared unless you */
  76.                             /* want to preserve the key buffer for each */
  77.                             /* access pack.  You read a gotten key from */
  78.                             /* here, and also specify key to find here */
  79.                             /* READ THE DOCS on exact matches, et al., */
  80.                             /* especially about "enumerator word", partial */
  81.                             /* match (follow with GetNext/Prev), and so on */
  82.                             
  83. long    recs2add;
  84. long    low;
  85. long    high;
  86. long    i;
  87.           
  88. #pragma pack()
  89.  
  90.  
  91. int main()
  92. {
  93.  
  94.    strcpy(fieldlist[0].fieldname, "CODENUMBER");
  95.    strcpy(fieldlist[0].fieldtype, "B");
  96.    fieldlist[0].fieldlen = 4;
  97.    fieldlist[0].fielddc = 0;
  98.    strcpy(fieldlist[1].fieldname, "CODENAME");
  99.    strcpy(fieldlist[1].fieldtype, "C");
  100.    fieldlist[1].fieldlen = 11;
  101.    fieldlist[1].fielddc = 0;
  102.  
  103.    /* excuses, excuses */
  104.  
  105.    printf("BC_LAI10.C - LONG INT, SIGNED, UNIQUE long int, add/reindex speed test\n");
  106.    printf("--uses non-standard data files with binary field values, not DBF\n");
  107.    printf(">> USING DIRECTORY : .\\ \n\n");
  108.  
  109.    level = 100;
  110.    MP.func = MEMORYXB;
  111.    rez = BULLET(&MP);
  112.    printf("memory avail   : %lu\n",MP.memory);
  113.  
  114.    if (MP.memory < 40000L) {
  115.       rez = 8;
  116.       goto Abend;
  117.    }
  118.               
  119.    level = 110;
  120.    IP.func = INITXB;
  121.    IP.jftmode = 0;
  122.    rez = BULLET(&IP);
  123.    if (rez != 0) goto Abend;
  124.  
  125. #if 0
  126.    level = 120;
  127.    EP.func = ATEXITXB;
  128.    rez = BULLET(&EP);
  129.    if (rez != 0) goto Abend;
  130. #endif
  131.  
  132.    level = 130;                /* disregard not found errors */
  133.    DFP.func = DELETEFILEDOS;
  134.    DFP.filenameptr = NameDAT;
  135.    rez = BULLET(&DFP);
  136.    DFP.filenameptr = NameIX1;
  137.    rez = BULLET(&DFP);
  138.  
  139.    level = 1000;
  140.    CDP.func = CREATEDXB;
  141.    CDP.filenameptr = NameDAT;
  142.    CDP.nofields = 2;
  143.    CDP.fieldlistptr = fieldlist;
  144.    CDP.fileid = 255;
  145.    rez = BULLET(&CDP);
  146.    if (rez !=0) goto Abend;
  147.  
  148.    level = 1010;
  149.    OP.func = OPENDXB;
  150.    OP.filenameptr = NameDAT;
  151.    OP.asmode = READWRITE | DENYNONE;
  152.    rez = BULLET(&OP);
  153.    if (rez !=0) goto Abend;
  154.    handdat = OP.handle;
  155.  
  156.    level = 1100;
  157.    CKP.func = CREATEKXB;
  158.    CKP.filenameptr = NameIX1;
  159.    CKP.keyexpptr = kx1;
  160.    CKP.xblink = handdat;
  161.    CKP.keyflags = cLONG | cSIGNED | cUNIQUE;
  162.    CKP.codepageid = -1;
  163.    CKP.countrycode = -1;
  164.    CKP.collateptr = NULL;
  165.    rez = BULLET(&CKP);
  166.    if (rez !=0) goto Abend;
  167.  
  168.    level = 1110;
  169.    OP.func = OPENKXB;
  170.    OP.filenameptr = NameIX1;
  171.    OP.asmode = READWRITE | DENYNONE;
  172.    OP.xblink = handdat;
  173.    rez = BULLET(&OP);
  174.    if (rez !=0) goto Abend;
  175.    handix1 = OP.handle;
  176.  
  177.    AP.func = ADDRECORDXB;
  178.    AP.handle = handdat;
  179.    AP.recptr = &testrec;
  180.    AP.keyptr = keybuffer;    /* set here and used throughout  */
  181.    AP.nextptr = NULL;
  182.  
  183.    testrec.tag = ' ';
  184.    strcpy(testrec.codename, "xxxSAMExxx");
  185.  
  186.    printf("Recs to add/reindex: ");
  187.    gets(tmpstr);
  188.    recs2add = atol(tmpstr);
  189.    if (recs2add == 0L) recs2add = 5L;
  190.  
  191.    level = 1200;
  192.    low = -3L;
  193.    high = low + recs2add - 1L;
  194.    printf("Adding %ld records ( keys %ld to %ld )... ",recs2add,low,high);
  195.  
  196.    time(&starttime);
  197.    for (i = low; i < (recs2add+low); i++) {
  198.       testrec.codenumber = i;
  199.       rez = BULLET(&AP);
  200.       if (rez !=0) goto Abend;
  201.    }
  202.    time(&endtime);
  203.    printf("%lu secs.\n",(endtime - starttime));
  204.  
  205.    level = 1210;
  206.    printf("Reindexing... ");
  207.    AP.func = REINDEXXB;
  208.    AP.handle = handix1;
  209.    time(&starttime);
  210.    rez = BULLET(&AP);
  211.    time(&endtime);
  212.    if (rez != 0) {
  213.       rez = AP.stat;    /* MUST take AP.stat since a xaction routine */
  214.       goto Abend;       /* see docs and !README2.TXT for more */
  215.    }
  216.    printf("%lu secs\n\n",(endtime - starttime));
  217.  
  218.    level = 1300;
  219.    AP.func = GETFIRSTXB;
  220.    rez = BULLET(&AP);
  221.    printf("  The first 5 key/recs\n");
  222.    printf("%7lu %7ld %.10s\n",AP.recno,testrec.codenumber,testrec.codename);
  223.    for (i=1;i < 5; i++) {
  224.       if (rez != 0) break;
  225.       AP.func = GETNEXTXB;
  226.       rez = BULLET(&AP);
  227.       printf("%7lu %7ld %.10s\n",AP.recno,testrec.codenumber,testrec.codename);
  228.    }
  229.    if (rez == 202) rez = 0;
  230.    if (rez != 0) goto Abend;
  231.    puts(" ");
  232.  
  233.    level = 1310;
  234.    AP.func = GETLASTXB;
  235.    rez = BULLET(&AP);
  236.    printf("  The last 5 key/recs\n");
  237.    printf("%7lu %7ld %.10s\n",AP.recno,testrec.codenumber,testrec.codename);
  238.    for (i=1;i < 5; i++) {
  239.       if (rez != 0) break;
  240.       AP.func = GETPREVXB;
  241.       rez = BULLET(&AP);
  242.       printf("%7lu %7ld %.10s\n",AP.recno,testrec.codenumber,testrec.codename);
  243.    }
  244.    if (rez == 203) rez = 0;
  245.    if (rez != 0) goto Abend;
  246.    
  247.    level = 1311;
  248.    printf("  Finding the last gotten key, (in AP.keybuffer already)\n");
  249.    AP.func = GETEQUALXB;
  250.    rez = BULLET(&AP);
  251.    printf("%7lu %7ld %.10s\n",AP.recno,testrec.codenumber,testrec.codename);
  252.    if (rez != 0) goto Abend;
  253.    
  254.    level = 1312;
  255.    printf("  Finding key of 5\n");
  256.    AP.func = GETEQUALXB;
  257.    *((long *)keybuffer) = 5L;
  258.    rez = BULLET(&AP);
  259.    printf("%7lu %7ld %.10s\n",AP.recno,testrec.codenumber,testrec.codename);
  260.    if (rez != 0) goto Abend;
  261.    
  262.    puts("Okay.");
  263.    EP.func = EXITXB;
  264.    rez = BULLET(&EP);
  265.    return(0);
  266.    /* program exit */
  267.  
  268.  
  269.    /*----------------------------------------------*/
  270.    /* that's right, we go to a termination routine */
  271.  
  272. Abend:
  273.    printf("Error: %u at level %u while performing ",rez,level);
  274.    switch (level) {
  275.    case 100:
  276.       printf("a memory request of 140K.\n");
  277.       break;
  278.    default:
  279.       printf("(See source)\n");    /* just check the source */
  280.    }
  281.  
  282.    exit(1);
  283. }
  284.  
  285.